<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2019/1/5
  Time: 8:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <title>Title</title>

    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.11.0.js"></script>
    <script type="text/javascript">
        function forward() {
            var categoryId= $("select[name='categoryId']").val();

            if(categoryId==0 || categoryId==null){
                alert("请选择类别");
                return;
            }
            window.location="${pageContext.request.contextPath}/book/save?categoryId="+categoryId;
        }


        function deleteBook(id) {
            if(!confirm("确定删除？")){
                return;
            }

            $.get("/book/delete",{id:id},function (result) {
                if (result=="1"){
                    alert("删除成功");
                }else {
                    alert("删除失败");
                }
                window.location=window.location;
            });
        }
    </script>

</head>
<body>
<form action="${pageContext.request.contextPath}/book/list" method="post">
                    图书分类：<select name="categoryId">
                    <option value="0">==类型==</option>
                    <c:forEach var="item" items="${plist}">
                        <option <c:if test="${item.id==bookEntry.categoryId}">selected="selected"</c:if> value="${item.id}">${item.name}</option>
                    </c:forEach>b
                </select>
                    <input type="submit" value="查询">
                    <input type="button" onclick="forward()" value="新增">
    </form>

    <table border="1" width="580">
        <tr><td colspan ="6" align="center" style="font-size:30px">电子图书列表</td></tr>
        <tr>
            <td>图书编号</td>
            <td>图书名称</td>
            <td>图书摘要</td>
            <td>上传人</td>
            <td>上传时间</td>
            <td>操作</td>
        </tr>
        <c:forEach items="${list}" var="li">
            <tr>
                <td>${li.id}</td>
                <td>${li.title}</td>
                <td>${li.summary}</td>
                <td>${li.uploaduser}</td>
                <td><fmt:formatDate value="${li.createdate}" pattern="yyyy-MM-dd HH:mm"/></td>
                <td>
                    <a href="${pageContext.request.contextPath}/book/update?id=${li.id}">修改</a>
                    <a href="javascript:void(0)" onclick="deleteBook(${li.id});">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <p>共${pageTool.totalRecordCount}条数据，当前第 ${pageTool.currPageNo}/${pageTool.pageCount}页,每页${pageTool.pageSize}条

        <a href="${pageContext.request.contextPath}/book/list?title=${bookEntry.title}&categoryId=${bookEntry.categoryId}&currPageNo=1">首页</a>
        <a href="${pageContext.request.contextPath}/book/list?title=${bookEntry.title}&categoryId=${bookEntry.categoryId}&currPageNo=${pageTool.currPageNo-1}">上一页</a>

        <c:forEach var="prePage" items="${prePages}">
            <a href="${pageContext.request.contextPath}/book/list?title=${bookEntry.title}&categoryId=${bookEntry.categoryId}&currPageNo=${prePage}">${prePage}</a>

        </c:forEach>
        <b >${pageTool.currPageNo}</b>
        <c:forEach var="nextPage" items="${nextPages}">
            <a href="${pageContext.request.contextPath}/book/list?title=${bookEntry.title}&categoryId=${bookEntry.categoryId}&currPageNo=${nextPage}">${nextPage}</a>

        </c:forEach>

        <a href="${pageContext.request.contextPath}/book/list?title=${bookEntry.title}&categoryId=${bookEntry.categoryId}&currPageNo=${pageTool.currPageNo+1}">下一页</a>
        <a href="${pageContext.request.contextPath}/book/list?title=${bookEntry.title}&categoryId=${bookEntry.categoryId}&currPageNo=${pageTool.pageCount}">末页</a>

    </p>

</body>
</html>
